package com.daryl.jcu_project1_creditscoreform;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Layout;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class Loan_application6 extends Activity {

	private Button addRealEstateBtn;
	private Button rmvRealEstateBtn;
	private Button addOtherPropertyLoanBtn;
	private Button rmvOtherPropertyLoanBtn;
	private Button nextPageBtn;
	private Button previousPageBtn;
	private LinearLayout loRealEstate1;
	private LinearLayout loRealEstate2;
	private LinearLayout loRealEstate3;
	private LinearLayout loRealEstate4;
	private LinearLayout loOtherPropertLoan1;
	private LinearLayout loOtherPropertLoan2;
	private LinearLayout loOtherPropertLoan3;
	private LinearLayout loOtherPropertLoan4;
	private int realEstate = 1;
	private int propertyLoan = 1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loan_application6);
		
		addRealEstateBtn = (Button) findViewById(R.id.addRealEstateBtn);
		addRealEstateBtn.setOnClickListener(addRealEstate());
		rmvRealEstateBtn = (Button) findViewById(R.id.removeRealEstateBtn);
		rmvRealEstateBtn.setOnClickListener(rmvRealEstate());
		addOtherPropertyLoanBtn = (Button) findViewById(R.id.addOtherPropertyLoanBtn);
		addOtherPropertyLoanBtn.setOnClickListener(addLoanProtperty());
		rmvOtherPropertyLoanBtn = (Button) findViewById(R.id.rmvOtherPropertyLoanBtn);
		rmvOtherPropertyLoanBtn.setOnClickListener(rmvLoanProperty());
		nextPageBtn = (Button) findViewById(R.id.nextPageBtn);
		nextPageBtn.setOnClickListener(nextPage());
		previousPageBtn = (Button) findViewById(R.id.backPageBtn);
		previousPageBtn.setOnClickListener(previousPage());
		loRealEstate1 = (LinearLayout) findViewById(R.id.layoutAssestSectionOtherRealEstate1);
		loRealEstate2 = (LinearLayout) findViewById(R.id.layoutAssestSectionOtherRealEstate2);
		loRealEstate3 = (LinearLayout) findViewById(R.id.layoutAssestSectionOtherRealEstate3);
		loRealEstate4 = (LinearLayout) findViewById(R.id.layoutAssestSectionOtherRealEstate4);
		loOtherPropertLoan1 = (LinearLayout) findViewById(R.id.layoutLiabilitiesSection1);
		loOtherPropertLoan2 = (LinearLayout) findViewById(R.id.layoutLiabilitiesSection2);
		loOtherPropertLoan3 = (LinearLayout) findViewById(R.id.layoutLiabilitiesSection3);
		loOtherPropertLoan4 = (LinearLayout) findViewById(R.id.layoutLiabilitiesSection4);
	}
	
	private OnClickListener addLoanProtperty() {
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				if(propertyLoan == 1){
					loOtherPropertLoan1.setVisibility(View.VISIBLE);
					rmvOtherPropertyLoanBtn.setVisibility(View.VISIBLE);
				}
				if(propertyLoan == 2)
				{
					loOtherPropertLoan2.setVisibility(View.VISIBLE);
				}
				if(propertyLoan == 3)
				{
					loOtherPropertLoan3.setVisibility(View.VISIBLE);
				}
				if(propertyLoan == 4)
				{
					loOtherPropertLoan4.setVisibility(View.VISIBLE);
					addOtherPropertyLoanBtn.setVisibility(View.INVISIBLE);
				}
				propertyLoan++;
			}
		
			};
	}
	
	
	private OnClickListener rmvLoanProperty() {
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				if(propertyLoan == 2){
					loOtherPropertLoan1.setVisibility(View.GONE);
				rmvOtherPropertyLoanBtn.setVisibility(View.GONE);
				}
				if(propertyLoan == 3)
				{
					loOtherPropertLoan2.setVisibility(View.GONE);
				}
				if(propertyLoan == 4)
				{
					loOtherPropertLoan3.setVisibility(View.GONE);
				}
				if(propertyLoan == 5)
				{
					loOtherPropertLoan4.setVisibility(View.GONE);
					addOtherPropertyLoanBtn.setVisibility(View.VISIBLE);
				}
				propertyLoan--;
			}
		
			};
	}
	
	
	private OnClickListener addRealEstate() {
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				if(realEstate == 1){
				loRealEstate1.setVisibility(View.VISIBLE);
				rmvRealEstateBtn.setVisibility(View.VISIBLE);
				}
				if(realEstate == 2)
				{
					loRealEstate2.setVisibility(View.VISIBLE);
				}
				if(realEstate == 3)
				{
					loRealEstate3.setVisibility(View.VISIBLE);
				}
				if(realEstate == 4)
				{
					loRealEstate4.setVisibility(View.VISIBLE);
					addRealEstateBtn.setVisibility(View.INVISIBLE);
				}
				realEstate++;
			}
		
			};
	}
	
	private OnClickListener rmvRealEstate() {
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				if(realEstate == 2){
				loRealEstate1.setVisibility(View.GONE);
				rmvRealEstateBtn.setVisibility(View.INVISIBLE);
				}
				if(realEstate == 3)
				{
					loRealEstate2.setVisibility(View.GONE);
				}
				if(realEstate == 4)
				{
					loRealEstate3.setVisibility(View.GONE);
				}
				if(realEstate == 5)
				{
					loRealEstate4.setVisibility(View.GONE);
					addRealEstateBtn.setVisibility(View.VISIBLE);
				}
				realEstate--;
			}
		
			};
	}
	
	private OnClickListener nextPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				
				Intent intent = new Intent(context, Loan_application7.class);
                startActivity(intent);
			}
		
			};
	}
	private OnClickListener previousPage() {
		return new OnClickListener() {
			public void onClick(View v) {
			}
		
			};
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_loan_application6, menu);
		return true;
	}

}
